package com.business.action.wechat;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.wechat.service.WeixinService;
import com.business.wechat.service.WeixinUtils;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import net.sf.rose.jdbc.PageBean;

/**
 * @author: fengjian
 * @date: 2018/08/20
 * @description:测试
 *
 */
@Controller
@RequestMapping("/weixin/test")
public class WechatTestAction {

	/**
	 * 给指定用户推送消息
	 * @param request
	 * @return
	 * @throws WxErrorException
	 */
	@ResponseBody
	@RequestMapping("/notify.do")
	public PageBean notify(HttpServletRequest request) throws WxErrorException {
		PageBean page = new PageBean();
		WeixinService weixinService = WeixinUtils.getWeixinBean("platform");
    	WxMpTemplateMessage wt = new WxMpTemplateMessage();
    	wt.setToUser("oG-tD0e38ijt8uMDyHbPYEbgcSU4");
    	wt.setTemplateId("CuYbG89jvNb8XPGFJpwTyPMj3D2-pGPerZN-Ei2iPpw");
    	wt.setUrl("http://www.baidu.com");
    	WxMpTemplateData d = new WxMpTemplateData();
    	d.setName("11");
    	d.setValue("22");
    	wt.addData(d);
    	weixinService.getMpService().getTemplateMsgService().sendTemplateMsg(wt);
    	page.setData(wt);
		return page;
	}

}